package com.xh.demo.commons.exception;


import com.xh.demo.commons.message.CommonMessage;

/**
* @apiNote 业务异常类
* @author wen
* @since 2021/12/11
*/
public class BusinessException extends RuntimeException implements CommonMessage {

    private final int code;

    private final String msg;

    public BusinessException(CommonMessage CommonMessage) {
        this.code = CommonMessage.getCode();
        this.msg = CommonMessage.getMsg();
    }

    public BusinessException(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static BusinessException build(CommonMessage CommonMessage) {
        return new BusinessException(CommonMessage);
    }

    @Override
    public int getCode() {
        return this.code;
    }

    @Override
    public String getMsg() {
        return this.msg;
    }
}
